/**
 * 选择提醒设置类型
 */
import React, { Component, PropTypes } from 'react';
import { Utility, GxIcon } from 'components';
import { connect } from 'react-redux';
import * as CommonActions from 'redux/modules/reduxCommon';

const styles = require('./scss/SelectWorkWay.scss');

@connect(
  state => ({
    Title: state.Common.Title,                                                               // 标题
    UrlParams: state.Common.UrlParams,                                                       // URL参数
    SelectWorkWayData: state.Common[Utility.constItem.StateName.SelectWorkWay],              //
  }),
  { ...CommonActions })

export default class SelectWorkWay extends Component {
  static propTypes = {
    Title: PropTypes.string,                                            // 标题
    UrlParams: PropTypes.object,                                        // url 参数
    onSetContent: PropTypes.func,                                       // 
  };

  constructor(props) {
    super(props);
    const { WorkWay } = Utility.constItem.StateInfo;
    this.state = { WorkWay };
    const { SelectWorkWayData } = props;
    this.state.CurrentItem = SelectWorkWayData || WorkWay[0];
  }

  componentDidMount() {
    this.state.IsMount = true;
    const { } = Utility;
  }

  componentWillUnmount() {
    delete this.state.IsMount;
  }

  /**
   * 更新渲染
   */
  __UpdateRender() {
    if (!!this.state.IsMount) {
      this.setState({ __CurrentTempDate: new Date().getTime() });
    }
  }

  __HandlerSelectItem(item) {
    this.state.CurrentItem = item;
    this.__UpdateRender();
  }

  __BuildHtml() {
    const { WorkWay, CurrentItem } = this.state;
    return WorkWay.map((item, index) => {
      return (<div key={index} className={styles.type} onClick={this.__HandlerSelectItem.bind(this, item)}>
        <div className={styles.title}>{item.Title}</div>
        <div className={styles.icon}>
          <GxIcon IconType="iconRadio" IsSelect={item === CurrentItem} />
        </div>
      </div>);
    });
  }

  __HandlerSubmit() {
    console.log(' submit...');
    const { onSetContent } = this.props;
    if (Utility.isFunction(onSetContent)) {
      onSetContent(Utility.constItem.StateName.SelectWorkWay, this.state.CurrentItem);
    }
    Utility.$goBack();
  }

  render() {
    const { } = this.state;

    return (
      <div className={styles.selectWorkWayCss}>
        <div className={styles.plan}>
          {
            this.__BuildHtml()
          }
        </div>

        <div className={styles.btns}>
          <div onClick={this.__HandlerSubmit.bind(this)}>确认</div>
        </div>
      </div>
    );
  }
}

